{layout name="layout1" /}
<style>
    .layui-table-cell {
        height: auto;
    }
</style>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-collapse like-layui-collapse" lay-accordion="" style="border:1px dashed #c4c4c4">
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title like-layui-colla-title" style="background-color: #fff">操作提示</h2>
                    <div class="layui-colla-content layui-show">
                        <p>*佣金提现申请记录；</p>
                        <p>*佣金才能提现，充值的金额不允许提现；</p>
                        <p>*佣金提现支持微信、支付宝转账。佣金提现申请审核通过即代表已转账，申请审核失败佣金会退回佣金账户；</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">提现信息:</label>
                    <div class="layui-input-inline" style="width: 200px;">
                        <select name="search_key" id="search_key">
                            <option value="order_sn">提现单号</option>
                            <option value="user_sn">会员编号</option>
                            <option value="nickname">会员昵称</option>
                            <option value="mobile">手机号码</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="width: 200px;">
                        <input type="text" id="keyword" name="keyword" placeholder="请输入关键词" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">提现方式：</label>
                    <div class="layui-input-inline">
                        <select name="type" id="type">
                            <option value="">全部</option>
                            {foreach $type as $item => $val}
                            <option value="{$item}">{$val}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">提现状态：</label>
                    <div class="layui-input-inline">
                        <select name="status" id="status">
                            <option value="">全部</option>
                            {foreach $status as $key => $item}
                            <option value="{$key}">{$item}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">提现时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input time" id="start_time" name="start_time"  autocomplete="off">
                    </div>
                    <div class="layui-input-inline" style="margin-right: 5px;width: 10px;">
                        <label class="layui-form-mid">-</label>
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input time" id="end_time" name="end_time"  autocomplete="off">
                    </div>
                </div>

                <div class="layui-inline">
                    <div class="layui-btn-group">
                        <button type="button" id="today" day="1" class="layui-btn layui-btn-sm layui-btn-normal day">今天</button>
                        <button type="button"  day="-1" class="layui-btn layui-btn-sm layui-btn-primary day">昨天</button>
                        <button type="button"  day="7" class="layui-btn layui-btn-sm layui-btn-primary day">近7天</button>
                        <button type="button"  day="30" class="layui-btn layui-btn-sm layui-btn-primary day">近30天</button>
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm layuiadmin-btn-withdraw {$view_theme_color}" lay-submit lay-filter="withdraw-search">查询</button>
                    <button class="layui-btn layui-btn-sm layuiadmin-btn-withdraw layui-btn-primary }" lay-submit lay-filter="withdraw-clear-search">清空查询</button>
                </div>
            </div>

        </div>

        <div class="layui-card-body">
            <table id="withdraw-lists" lay-filter="withdraw-lists"></table>

            <script type="text/html" id="img-info">
                <img src="{{d.money_qr_code}}" style="height:80px;width: 80px" class="image-show">
            </script>

            <script type="text/html" id="withdraw-operation">
                {{#  if(d.status == 0){ }}
                <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="pass">审核通过</a>
                <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="refuse">审核拒绝</a>
                {{#  } }}
            </script>
        </div>
    </div>
</div>

<script>
    layui.config({
        base: '/static/plug/layui-admin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table','like','laydate'], function(){
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table
            ,like = layui.like
            ,laydate = layui.laydate;

        //日期时间范围
        laydate.render({
            elem: '#start_time'
            , type: 'datetime'
            ,theme: '#1E9FFF'
            , value: "{$today[0]}"
        });

        laydate.render({
            elem: '#end_time'
            , type: 'datetime'
            ,theme: '#1E9FFF'
            ,value: "{$today[1]}"
        });

        //监听搜索
        form.on('submit(withdraw-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('withdraw-lists', {
                where: field
            });
        });

        //清空查询
        form.on('submit(withdraw-clear-search)', function(){
            $('#keyword').val('');
            $('#status').val('');
            $('#type').val('');
            $('#start_time').val('{$today[0]}');
            $('#end_time').val('{$today[1]}');
            $('#today').trigger("click");
            form.render('select');
            //刷新列表
            table.reload('withdraw-lists', {
                where: []
            });
        });


        table.render({
            id:'withdraw-lists'
            ,elem: '#withdraw-lists'
            ,url: '{:url("withdraw/lists")}'
            ,cols: [[
                {field: 'sn',title: '提现单号', width:180}
                ,{field: 'nickname', title: '会员昵称', width:120}
                ,{field: 'user_sn', title: '会员编号', width:120}
                ,{field: 'mobile', title: '手机号码', width:120}
                ,{field: 'money', title: '提现金额', width:100}
                ,{field: 'poundage', title: '手续费', width:100}
                ,{field: 'left_money', title: '转账金额', width:100}
                ,{field: 'type', title: '提现方式', align:'center', width:100}
                ,{field: 'account', title: '提现账户', width:120}
                ,{field: 'money_qr_code', title: '收款码', templet:'#img-info', width:150}
                ,{field: 'real_name', title: '真实姓名', width:100,align:'center'}
                ,{field: 'status_text', title: '提现状态', align:'center', width:100}
                ,{fixed: 'right', title: '操作', align: 'center', toolbar: '#withdraw-operation',width:200}
            ]]
            ,page:true
            ,text: {none: '暂无数据！'}
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                return {
                    "code":res.code,
                    "msg":res.msg,
                    "count": res.data.count, //解析数据长度
                    "data": res.data.lists, //解析数据列表
                };
            }
            ,done: function(res, curr, count){
                // 解决操作栏因为内容过多换行问题
                $(".layui-table-main tr").each(function (index, val) {
                    $($(".layui-table-fixed-l .layui-table-body tbody tr")[index]).height($(val).height());
                    $($(".layui-table-fixed-r .layui-table-body tbody tr")[index]).height($(val).height());
                });
            }
        });


        table.on('tool(withdraw-lists)', function(obj){
            var id = obj.data.id;
            var nickname = obj.data.nickname;
            if(obj.event === 'pass'){
                var confirm_text = '确定审核通过佣金提现申请:'+ "<span style='color: red'>"+nickname+"</span>";
                layer.confirm(confirm_text, function(index){
                    like.ajax({
                        url:'{:url("withdraw/confirm")}',
                        data:{'id':id},
                        type:"post",
                        success:function(res)
                        {
                            if(res.code == 1)
                            {
                                layui.layer.msg(res.msg, {
                                    offset: '15px'
                                    , icon: 1
                                    , time: 1000
                                });
                                layer.close(index); //关闭弹层
                                table.reload('withdraw-lists'); //数据刷新
                            }
                        }
                    });
                });
            }

            if(obj.event === 'refuse'){
                var confirm_text = '确定审核拒绝佣金提现申请:'+ "<span style='color: red'>"+nickname+"</span>";
                layer.confirm(confirm_text, function(index){
                    like.ajax({
                        url:'{:url("withdraw/refuse")}',
                        data:{'id':id},
                        type:"post",
                        success:function(res)
                        {
                            if(res.code == 1)
                            {
                                layui.layer.msg(res.msg, {
                                    offset: '15px'
                                    , icon: 1
                                    , time: 1000
                                });
                                layer.close(index); //关闭弹层
                                table.reload('withdraw-lists'); //数据刷新
                            }
                        }
                    });
                });
            }
        });


        $('.day').click(function(){
            $('.day').removeClass('layui-btn-normal');
            $('.day').removeClass('layui-btn-primary');
            $('.day').addClass('layui-btn-primary');
            $(this).removeClass('layui-btn-primary');
            $(this).addClass('layui-btn-normal');
            var day = $(this).attr('day');
            switch (day) {
                case '-1':
                    $('#start_time').val('{$yesterday[0]}');
                    $('#end_time').val('{$yesterday[1]}');
                    break;
                case '1':
                    $('#start_time').val('{$today[0]}');
                    $('#end_time').val('{$today[1]}');
                    break;
                case '7':
                    $('#start_time').val('{$days_ago7[0]}');
                    $('#end_time').val('{$days_ago7[1]}');
                    break;
                case '30':
                    $('#start_time').val('{$days_ago30[0]}');
                    $('#end_time').val('{$days_ago30[1]}');
                    break;
            }
        });

    });

</script>